package com.sskj.b70.p.activity;

import com.lzy.okgo.model.Response;
import com.sskj.b70.m.HttpConfig;
import com.sskj.b70.m.bean.HttpData;
import com.sskj.b70.m.http.HttpUtil;
import com.sskj.b70.m.http.JsonCallBack;
import com.sskj.b70.p.base.BasePresenter;
import com.sskj.b70.utils.ToastUtil;
import com.sskj.b70.v.activity.PwdResetActivity;

/**
 * <pre>
 *     author : wk_math
 *     e-mail : wk_math@163.com
 *     time   : 2018/03/30
 *     desc   :
 *     version: 1.0
 * </pre>
 */

public class PwdResetPresenter extends BasePresenter<PwdResetActivity> {
    /**
     * 找回密码
     *
     * @param mobile
     * @param password
     * @param code
     */
    public void reset(String mobile, String password, String code) {
        HttpUtil.forgetPwd(mobile, password, code)

                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.getMsg());
                        if (httpData.getStatus() == HttpConfig.STATUS_OK) {
                            mView.resetSuccess();
                        }
                    }
                });
    }
    public void resetWithEmail(String email,String pwd,String code){
        httpService.resetPwdWithEmail(email,pwd,code)
                .execute(new JsonCallBack<HttpData>() {
                    @Override
                    protected void _onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.getMsg());
                        if (httpData.getStatus() == HttpConfig.STATUS_OK) {
                            mView.resetSuccess();
                        }
                    }
                });
    }

    /**
     * 修改密码
     *
     * @param account
     * @param passwordOrigin
     * @param password
     */
    public void resetWithOrigin(String account, String passwordOrigin, String password) {
        httpService.resetPwd(account, passwordOrigin, password)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.getMsg());
                        if (httpData.getStatus() == HttpConfig.STATUS_OK) {
                            mView.resetSuccess();
                        }
                    }
                });
    }
}
